@extends('develop.layoutEdit')

@section('title')

    <li class="cur">
        <span>退货设置</span>
    </li>

@endsection


@section('css')
    <style>
        .layer-go-back{
            display:none;
        }
    </style>
@endsection

@section('content')

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*&nbsp;</span>退货服务状态：</label>
        <div class="col-sm-9">
            <div class="layui-form">
                <input type="radio" name="bill_return_status"  value="1"  lay-filter="no_check"title="开启" @if( isset($configure['bill_return_status']) && $configure['bill_return_status'] == 1 ) checked @endif>
                <input type="radio" name="bill_return_status"  value="0" lay-filter="check" title="关闭" @if( isset($configure['bill_return_status']) && $configure['bill_return_status'] == 0 ) checked @endif>
            </div>
        </div>
    </div>

    <div id="bill_return" @if( $configure['bill_return_status'] == 0 ) style="display: none;"@endif>

        <div class="form-group">
            <label class="col-sm-3 control-label"><span class="red pr5">*&nbsp;</span>是否允许客户自主退货：</label>
            <div class="col-sm-9">
                <div class="layui-form">
                    <input type="radio" name="bill_return_by_oneself"  value="1"  title="是" @if( isset($configure['bill_return_by_oneself']) && $configure['bill_return_by_oneself'] == 1 ) checked @endif>
                    <input type="radio" name="bill_return_by_oneself"  value="0" title="否" @if( isset($configure['bill_return_by_oneself']) && $configure['bill_return_by_oneself'] == 0 ) checked @endif>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label"><span class="red pr5">*&nbsp;</span>审核方式：</label>
            <div class="col-sm-9">
                <div class="layui-form">
                    <input type="radio" name="audit_way"  value="0" title="自动审核" @if( isset($configure['audit_way']) && $configure['audit_way'] == 0 ) checked @endif>
                    <input type="radio" name="audit_way"  value="1" title="人工审核" @if( isset($configure['audit_way']) && $configure['audit_way'] == 1 ) checked @endif>
                    <input type="radio" name="audit_way"  value="2" title="接口审核" @if( isset($configure['audit_way']) && $configure['audit_way'] == 2 ) checked @endif>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label"><span class="red pr5">*&nbsp;</span>退货方式：</label>
            <div class="col-sm-9">
                <div class="layui-form">
                    <input type="radio" name="bill_return_goods_way"  value="1" title="依据订单配送方式" @if( !isset($configure['bill_return_goods_way']) || $configure['bill_return_goods_way'] == 1 ) checked @endif>
                    <input type="radio" name="bill_return_goods_way"  value="2" title="快递" @if( isset($configure['bill_return_goods_way']) && $configure['bill_return_goods_way'] == 2 ) checked @endif>
                </div>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label" for="return_term_of_validity"><span class="red pr5">*&nbsp;</span>退货退款有效期：</label>
            <div class="col-sm-2">
                <input type="text" placeholder="退货退款有效期"  name="return_term_of_validity" id="return_term_of_validity" value="{{ $configure['return_term_of_validity']  }}" class="form-control">
                <span class="help-block">单位为天</span>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label"><span class="red pr5">*&nbsp;</span>退货信息：</label>
            <div class="col-sm-5">
                <textarea placeholder="退货信息"  id="bill_return_message" name="bill_return_message" rows="3" class="form-control">{{ $configure['bill_return_message'] }}</textarea>
            </div>
        </div>

        <div class="form-group">
            <label class="col-sm-3 control-label"><span class="red pr5">*&nbsp;</span>服务须知：</label>
            <div class="col-sm-5">
                <textarea placeholder="服务须知"  id="service_notes" name="service_notes" class="form-control description">{{ $configure['service_notes'] }}</textarea>
            </div>
        </div>

    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"></label>
        <div class="col-sm-9">
            <input type="hidden" name="function_id" id="function_id" value="{{ $function_id or ''}}">
            <input type="button"  value="保存" onclick="func.edit();" class="btn btn-success" >
        </div>
    </div>

@endsection

@section('js')

    <link rel="stylesheet" href="/framework/kindeditor/themes/default/default.css?v=20140227" type="text/css" media="screen" />
    <script src="/framework/kindeditor/kindeditor-all.js?v=201704051935" type="text/javascript"></script>
    <script src="/framework/kindeditor/lang/zh_CN.js" type="text/javascript"></script>
    <script>

        window.editor = KindEditor.create("#service_notes",{
            allowFileManager : true,
                minWidth:'400px',
                height:'200px;'
        });

        layui.use(['form'], function(){
            var form = layui.form();

            form.on('radio(check)', function(data){
                if ( this.checked ) {
                    $("#bill_return").hide();
                }
            });
            form.on('radio(no_check)', function(data){
                if ( this.checked ) {
                    $("#bill_return").show();
                }
            });
        });

        var func = {

            //保存
            edit:function(){

                var message_log = '' ;
                var configure = E.getFormValues('edit-form') ;
                configure.service_notes = E.trim( editor.html() );  //服务须知
                //参数判断
                if( E.isEmpty( configure.function_id ) || !E.isInt( configure.function_id ) ) {
                    message_log += '参数错误<br/>' ;
                }
                if( E.isEmpty( configure.return_term_of_validity )  ) {
                    message_log += '退货退款有效期不能为空<br/>' ;
                }
                if( E.isEmpty( configure.bill_return_message )  ) {
                    message_log += '退货信息不能为空<br/>' ;
                }
                if( E.isEmpty( configure.service_notes )  ) {
                    message_log += '服务须知不能为空<br/>' ;
                }
                if( message_log ) {
                    layer.alert( message_log , { icon:2 });
                    return false ;
                }

                layer.confirm("您确认保存该设置吗？",{icon:3,offset:'50px'}, function ( index ){
                    layer.close( index );
                    E.ajax( {
                        type:'get',
                        url: '/lar/develop/function/store/'+function_id,
                        data: configure,
                        dataType:'json',
                        // 返回值判断
                        success: function ( obj ){

                            if ( obj.code == 200 ) {
                                layer.alert( obj.message , { icon: 1,time : 1500 } ) ;
                            } else {
                                layer.alert( obj.message , { icon: 2 } ) ;
                            }
                        }
                    } ) ;
                });
            }

        };

    </script>
@endsection